package view;
import javax.swing.JPanel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.table.DefaultTableModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JScrollPane;
import java.util.Vector;
import javax.swing.JTable;
import javax.swing.JTree;
import javax.swing.JTextField;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.JFormattedTextField;
import javax.swing.JList;
import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.JSplitPane;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Color;
import javax.swing.ImageIcon;

public class InfoPanel extends JPanel{
	private InfoPanelTM iptm;
	private static String[] columnNames = {"Name", "Value"};
	private JTextField txtTypeTextTo;
	private JTree courseTree;
	private JLabel lblinfo;
	private JTextField txtCourseName;
	private JTextField txtProductFamily;
	private JTextField txtAbbr;
	
	public JButton btnClose;
	public InfoPanel(String InfoTitle) {
		
		JSplitPane splitPane = new JSplitPane();
		splitPane.setForeground(Color.ORANGE);
		splitPane.setOneTouchExpandable(true);
		
		JPanel panel = new JPanel();
		splitPane.setLeftComponent(panel);
		
		txtProductFamily = new JTextField();
		txtProductFamily.setText("Product family");
		txtProductFamily.setColumns(10);
		
		JLabel lblProductFamily = new JLabel("Product family:");
		lblinfo = new JLabel("Infomation");
		
		JLabel lblCourseName = new JLabel("Course name:");
		
		txtCourseName = new JTextField();
		txtCourseName.setText("Course name");
		txtCourseName.setColumns(10);
		
		JLabel lblAbbreviation = new JLabel("Abbreviation:");
		
		txtAbbr = new JTextField();
		txtAbbr.setText("Abbr.");
		txtAbbr.setColumns(10);
		
		JLabel lblVersion = new JLabel("Version:");
		
		JFormattedTextField frmtdtxtfldVersion = new JFormattedTextField();
		frmtdtxtfldVersion.setText("Version");
		
		JLabel lblCanSetupOn = new JLabel("Can setup on Pods:");
		
		JList list = new JList();
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, gl_panel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
						.addComponent(list, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE)
						.addComponent(txtAbbr, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE)
						.addComponent(txtProductFamily, Alignment.LEADING, 203, 203, Short.MAX_VALUE)
						.addComponent(lblinfo, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(lblProductFamily, Alignment.LEADING)
						.addComponent(lblCourseName, Alignment.LEADING)
						.addComponent(txtCourseName, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE)
						.addComponent(lblAbbreviation, Alignment.LEADING)
						.addComponent(lblVersion, Alignment.LEADING)
						.addComponent(frmtdtxtfldVersion, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE)
						.addComponent(lblCanSetupOn, Alignment.LEADING))
					.addContainerGap())
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblinfo)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(lblProductFamily)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(txtProductFamily, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(lblCourseName)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(txtCourseName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(lblAbbreviation)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(txtAbbr, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(lblVersion)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(frmtdtxtfldVersion, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(lblCanSetupOn)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(list, GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE)
					.addContainerGap())
		);
		panel.setLayout(gl_panel);
		
		JPanel panel_1 = new JPanel();
		splitPane.setRightComponent(panel_1);
		
		courseTree = new JTree();
		
		txtTypeTextTo = new JTextField();
		txtTypeTextTo.setText("Type text to search");
		txtTypeTextTo.setColumns(10);
		
		JToolBar toolBar = new JToolBar();
		toolBar.setFloatable(false);
		
		JButton btnNew = new JButton("");
		btnNew.setToolTipText("Add");
		btnNew.setIcon(new ImageIcon(InfoPanel.class.getResource("/resources/add-icon.png")));
		toolBar.add(btnNew);
		
		JButton btnDel = new JButton("");
		btnDel.setToolTipText("Del");
		btnDel.setIcon(new ImageIcon(InfoPanel.class.getResource("/resources/delete-icon.png")));
		toolBar.add(btnDel);
		
		JButton btnOK = new JButton("");
		btnOK.setToolTipText("Save");
		btnOK.setIcon(new ImageIcon(InfoPanel.class.getResource("/resources/Actions-dialog-ok-apply-icon.png")));
		toolBar.add(btnOK);
		
		btnClose = new JButton("");
		btnClose.setToolTipText("Close");
		btnClose.setIcon(new ImageIcon(InfoPanel.class.getResource("/resources/Actions-project-development-close-icon.png")));
		toolBar.add(btnClose);
		GroupLayout gl_panel_1 = new GroupLayout(panel_1);
		gl_panel_1.setHorizontalGroup(
			gl_panel_1.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_panel_1.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
						.addComponent(courseTree, GroupLayout.DEFAULT_SIZE, 305, Short.MAX_VALUE)
						.addComponent(txtTypeTextTo, GroupLayout.DEFAULT_SIZE, 305, Short.MAX_VALUE)
						.addComponent(toolBar, GroupLayout.DEFAULT_SIZE, 305, Short.MAX_VALUE))
					.addContainerGap())
		);
		gl_panel_1.setVerticalGroup(
			gl_panel_1.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_1.createSequentialGroup()
					.addGap(5)
					.addComponent(txtTypeTextTo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(courseTree, GroupLayout.PREFERRED_SIZE, 392, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(toolBar, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(7, Short.MAX_VALUE))
		);
		panel_1.setLayout(gl_panel_1);
		iptm = new InfoPanelTM(columnNames);
		setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		add(splitPane);
	}
	
	public void setCourseName(String text){
		lblinfo.setText(text);
	}
	
	public void loadCourseInfo(Vector<String> ItemsArray)
	{
		//comboBox.setModel(new DefaultComboBoxModel(ItemsArray));
	}
	
	protected void cleanProperties()
	{
		while (iptm.getRowCount()>0)
		{
			iptm.removeRow(0);
		}
	}
	
	protected void addProperties(String pName, Object value)
	{
		Vector rowData = new Vector();
		rowData.add(pName);
		rowData.add(value);
		iptm.addRow(rowData);
	}
}

class InfoPanelTM extends DefaultTableModel {	

	private Vector dataRow;
	private Vector<String> columnNames;		

	public InfoPanelTM (String[] _strColNames)
	{
		dataRow = new Vector();
		columnNames = new Vector<String>();
		for (int i=0; i<_strColNames.length; i++)
		{
			columnNames.add(_strColNames[i]);
		}
		
		try {
			setDataVector(dataRow, columnNames);
		}
		catch (ArrayIndexOutOfBoundsException e){			
			
		}
	}
	
	public void addData(Vector<Vector> data)
	{
		setDataVector(data, columnNames);
	}
	
	@Override
	public boolean isCellEditable(int row, int column) {
		if (column > 0){
        return true;
		}
		else{
			return false;
		}
    }
	
	public Vector<String> getColumnNames()
	{
		return columnNames;
	}
}


